/**
 * Created by lijing on 2016-06-22.
 */
$.validator.setDefaults({
    submitHandler: function () {
        savePub();
    }
});
$(document).ready(function () {
    validate();
    $("#educationName").click(function () {
        $("#educationName").cate({
            title: "学历",
            url: G_Path.path + "/sys/tag/category",
            param: {"dictCode": "EDUCATION"},
            liveSearch: false,
            "id": "education",
            "name": "educationName"
        });
    });
    $("#workExperienceName").click(function () {
        $("#workExperienceName").cate({
            title: "工作年限",
            url: G_Path.path + "/sys/tag/category",
            param: {"dictCode": "WORKEXPERIENCE"},
            liveSearch: false,
            "id": "workExperience",
            "name": "workExperienceName"
        });
    });
    $("#addressName").click(function () {
        $("#addressName").cate({
            title: "上班地址",
            dataId:"id",
            dataName:"address",
            url: G_Path.path + "/user/company/address/json",
            param: {"dictCode": ""},
            liveSearch: false,
            "id": "address",
            "name": "addressName"
        });
    });
});

function savePub() {
    $.post(G_Path.path + "/job/save", $("#mainForm").serialize(), function (text) {
        var data = $.parseJSON(text);
        if(data.success){
            if ("view" == status) {
                history.back();
            } else {
                window.close();
            }
        }
    });
}

function  validate(){
    //设置默认属性
    $("#mainForm").validate({
        rules: {
            name: {
                required: true,
                minlength: 1
            }
        },
        messages: {
            name: {
                required: "请输入名称",
                minlength: ""
            }
        }
    });
}